//导入 db 函数
const db = require('./db/db');
const mongoose = require('mongoose');
const MovieModel = require('./models/MovieModel');

//调用函数
db(() => {
  //当连接成功的时候, 执行该回调
  MovieModel.create({
    name: '让子弹飞',
    actors: ['姜文','葛优','周润发'],
    releaseYear: 2010
  }, (err, data) => {
    //判断
    if(err) throw err;
    //输出 data 的值,  data 是插入成功之后的文档对象
    console.log(data);
    //8. 关闭数据库连接  (可选)
    mongoose.connection.close();
  });

}, () => {
  console.log('连接失败~~');
});

  


